<template>
  <page-wrap stay-still back hide-tab title="职位列表">
    <view class="job-list">
      <scroll-view scroll-y @scrolltolower="handleMore" class="scroll-views">
        <template v-if="postList.length">
          <view
            class="post"
            v-for="(item, index) in postList"
            :key="index"
            @click="handleJobItem(item)"
          >
            <view class="post-left">
              <view  class="post-name">
                <text>{{ item.jtzw }}</text>
              </view>
              <view class="post-require">
                <text class="post-region">{{
                  item.workplace || "地区不限"
                }}</text>
                <text class="divider">|</text>
                <text class="post-edu"> {{ item.edus || "学历不限" }} </text>
                <text class="divider">|</text>
                <text class="post-exp"> {{ item.gznum || "经验不限" }} </text>
              </view>
            </view>
            <view class="post-right">
              <view  class="post-salary">
                <text>{{ item.salary }}</text>
              </view>
              <view class="post-date">
                <text >{{ formatTime(item.idate, 'MM月dd日') }}</text>
              </view>
            </view>
          </view>
          <u-loadmore
            class="job-more"
            :status="moreLoading"
            :load-text="loadText"
        /></template>
        <u-empty text="暂无数据" v-else></u-empty>
      </scroll-view>
    </view>
  </page-wrap>
</template>

<script>
import { getCompanyZpList } from "@/api/index";
import { formatTime } from '@/utils/handle'
export default {
  data() {
    return {
      chatId: "",
      companyId: "",
      jobpage: 0,
      postList: [],
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "没有更多了",
      },
      formatTime,
    };
  },

  onLoad(opt) {
    this.chatId = opt.chatId;
    if (this.chatId) {
      let chatArr = this.chatId.split("_");
      if (chatArr[1]) {
        this.companyId = chatArr[1];
      }
    }
    this.getCompanyZpList();
  },
  methods: {
    handleMore() {
      if (this.moreLoading != "nomore") this.getCompanyZpList();
    },
    getCompanyZpList() {
      let params = {
        company_id: this.companyId,
        conditionArr: {
          listtype: "pageList",
          page_size: "20",
          page: this.jobpage,
        },
      };
      params.conditionArr = JSON.stringify(params.conditionArr);
      this.moreLoading = "loading";
      getCompanyZpList(params).then((res) => {
        let data = res.data.data || res.data;
        if (data && data.length) {
          data = data.map(item => {
            if(item.idate) {
              item.idate = item.idate.replace(/-/g, '/');
            }
            return item
          })
          this.postList.push(...data);
          if (+res.page < +res.pages) {
            this.moreLoading = "loadmore";
            this.jobpage++;
          } else {
            this.moreLoading = "nomore";
          }
        } else {
          this.moreLoading = "nomore";
        }
      });
    },
    handleJobItem(item) {
      uni.navigateTo({
        url:
          "/pagesSub/message/chat/index?chatId=" +
          this.chatId +
          "&zpId=" +
          item.zp_id,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.job-list {
  background-color: $uni-bg-color;

  .post {
    display: flex;
    justify-content: space-between;
    padding: 32rpx;

    &-salary {
      margin-bottom: 12rpx;
      color: $u-type-primary;
    }

    &-require {
      color: $uni-text-color-999;
    }
    &-right {
      text-align: right;
    }
    &-name {
      margin-bottom: 12rpx;
    }
  }

  .divider {
    margin: 0 12rpx;
  }
}
</style>
